package com.css.ids.server.observer;

import java.util.LinkedHashMap;
import java.util.Map;

import com.css.ids.server.task.SendDataToClientTask;
import com.css.ids.server.task.ThreadPool;


public class BaseDataObserver {
	private Map<String,ClientInfo> clients = new LinkedHashMap<String,ClientInfo>();

	public void observe(byte[] data) {
		for (ClientInfo client : clients.values()) {
			SendDataToClientTask task = new SendDataToClientTask(data, client);
			ThreadPool.submit(task);
		}
	}
	
	public BaseDataObserver register(ClientInfo client) {
		clients.put(client.getUuid(),client);
		return this;
	}

	public BaseDataObserver remove(ClientInfo client) {
		clients.remove(client.getUuid());
		return this;
	}

	protected void init() {
		//可从数据库加载
	}
	
	

	private static BaseDataObserver instance = null;
	private BaseDataObserver() {
	}
	public static BaseDataObserver getInstance() {
		if (instance == null) {
			instance = new BaseDataObserver();
			instance.init();
		}
		return instance;
	}

}
